﻿using RQX.Common.Core.Extension;
using RQX.Common.Core.Hardware.BaseCollection;
using RQX.Common.Core.Hardware.Com;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TmpTest;
using static GE_B40.B40;

namespace GE_B40
{
    class Program
    {
        static void Main(string[] args)
        {
            //var msg = "7e8004c10a0000785d155f0000000000000000011601012c02014203010000ff0000000000000000006a5d155f3300000075126400018001800180018001000000010001800180018001800100000002000180018001800180000000000000018001800180018000000000000001800180018001800300000003010180018001800180030000000b000180030000000c000180000000000d000180000000000e000180030000000200be2564009a0201800701000009000400040001808f1d0000000000000180018000000000000001800180000000000100018001800180000000000000018001800180018001800180018001800300000004000180018001800180000000000000018001801f0001800180018000000000000001800000000000000180018001800180000000000000018001800180018000000000a1006a5d155f3380000075120180018001800000000000000000000000000000000000000000000000000000000000000000000000003300000075120180018001800180018001800180018001800180018001800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a1016a5d155f0000000000000180018001800180018000000000000000000000000000000180018001800180018001800180018001800180018001800180018001800180018001800180018001800180018001800180018001800180018001800180018001800000000000000180018001800180000000000000000001800180018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a1026a5d155f0000000000000180018001800180000000000000018001800180018001800180018001800180018001800180018000000000000000000000000000000000000000000180018000000000000001800180018001800180018001800180000000000000018000000000000000000000000000000000000000000000000000000100000000000180000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a1035e7e";
            //AnalysisData data = new AnalysisData(str);
            //var dic = data.Start();
            //dic.ForEach(item =>
            //    {
            //        Console.WriteLine($"{item.Key}\t{item.Value}");
            //    });



            //var buffer = msg[2..^2].HexStringToByte();
            //var record = buffer.ToStruct<datex_record>();// (datex_record)ByteToStruct(buffer, typeof(datex_record));
            //Dictionary<string, string> dic = new Dictionary<string, string>();
            //foreach (var item in record.ph_rcrd.ph_subrec)
            //{
            //    if (item.cl_drilvl_subt != 0 && (item.cl_drilvl_subt & 0x0F00) >> 8 == 0)
            //    {
            //        var basic = item.basic;

            //        try
            //        {
            //            dic.Add("hr", basic.ecg.hr.ToString());
            //            dic.Add("nibp_sys", basic.nibp.sys.ToString());
            //            dic.Add("nibp_dia", basic.nibp.dia.ToString());
            //            dic.Add("SpO2", basic.SpO2.SpO2.ToString());
            //            dic.Add("pr", basic.SpO2.pr.ToString());
            //            dic.Add("rr", basic.co2.rr.ToString());
            //            dic.Add("etco2", basic.co2.et.ToString());
            //            dic.Add("fio2", basic.o2.fi.ToString());
            //            dic.Add("t1", basic.t[0].temp.ToString());
            //        }
            //        catch(Exception ex)
            //        {
            //            int a = 1;
            //        }

            //    }
            //}
            //dic.ForEach(item =>
            //{
            //    Console.WriteLine($"{item.Key}\t{item.Value}");
            //});

            B40 tmp = new B40();
            StructureModel<MyCom> model = new StructureModel<MyCom>
            {
                Conn = new MyCom(tmp.BaudRate, "COM3", tmp.DataBits, tmp.StopBits, tmp.Parity, tmp.DTR, tmp.RTS)
            };
            B40 b40 = new B40(model);
            b40.DealDataHandler = (dic) =>
            {
                dic.ForEach(item =>
                {
                    Console.WriteLine($"{item.Key}\t{item.Value}");
                });
            };
            b40.Start();
            Console.ReadKey();
        }
    }
}
